package com.xtravel.common.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.xtravel.R;

public class DBHelper extends SQLiteOpenHelper
{

	private static final int DB_VERSION = 13;
	private static final String DB_NAME = "xtravel.db";

	private Context context;

	public DBHelper(Context context)
	{
		super(context, DB_NAME, null, DB_VERSION);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db)
	{
		String scripts = this.context.getResources().getString(R.string.sql_scripts);

		for (String script : scripts.split(";"))
		{
			db.execSQL(script);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		db.execSQL("drop table IF EXISTS UserFile;");
		db.execSQL("drop table IF EXISTS UserInfo;");
		String scripts = this.context.getResources().getString(R.string.sql_scripts);

		for (String script : scripts.split(";"))
		{
			db.execSQL(script);
		}
	}
}